﻿@{
	ViewBag.Title = "应收款管理";
}

@section header {
}
@section quickmenu {
	<td style="padding-right: 0px; padding-left: 10px;">
		<span style="cursor: pointer;" title="新建..." @@click="listAdd">
			<i class="icon-plus icon-2x pull-left icon-border crm-bu-style"></i>
		</span>
	</td>
	<td style="padding-right: 0px; padding-left: 10px;">
		<span style="cursor: pointer;" title="查找..." @@click="searchToggle">
			<i class="icon-search icon-2x pull-left icon-border crm-bu-style"></i>
		</span>
	</td>
	<td style="padding-right: 0px; padding-left: 10px;">
		<span style="cursor: pointer;" title="导出..." onclick="exportAll();"><i class="icon-upload icon-2x pull-left icon-border crm-bu-style"></i></span>
	</td>
}

@*页面视图列表开始*@
<table class="list_table table100">
	<tbody>
		<tr>
			<td style="">
				<i class="icon-filter pure-icon-bu"></i>视图: <span style="padding-right: 5px; ">
					&nbsp;&nbsp;<a class="cus_markbai tablink" href="javascript:void(0);">所有</a>&nbsp;&nbsp;
				</span>
			</td>
		</tr>
	</tbody>
</table>
@*页面视图列表结束*@

<div id="searchDiv" style="z-index: 1; display: block; position: relative; margin-top: 3px;" v-show="searchShow">
	<table cellpadding="5" cellspacing="2" class="searchUIBasic padding2" align="center" border="0" style="width:90%;">
		<tbody>
			<tr>
				<td class="small" nowrap="" align="center">
					<span>流水号</span>
					<input type="text" class="txtBox" style="width: 150px" v-model.trim="listConditions.sno">
					<span>布行名</span>
					<input type="text" class="txtBox" style="width: 180px" v-model.trim="listConditions.partnername">
					<span>应收日期</span>
					<input name="duedate_s" type="text" class="calendar" id="duedate_s" style="width: 70px;cursor:pointer;" maxlength="19" :value="listConditions.duedate_s" readonly />
					<i class="icon-calendar calendar-tgr" id="date_s_tgr"></i>&nbsp;-&nbsp;
					<input name="duedate_e" type="text" class="calendar" id="duedate_e" style="width: 70px;cursor:pointer;" maxlength="19" :value="listConditions.duedate_e" readonly />
					<i class="icon-calendar calendar-tgr" id="duedate_e_tgr"></i>
					<span>创建日期</span>
					<input name="date_s" type="text" class="calendar" id="date_s" style="width: 70px;cursor:pointer;" maxlength="19" :value="listConditions.date_s" readonly />
					<i class="icon-calendar calendar-tgr" id="date_s_tgr"></i>&nbsp;-&nbsp;
					<input name="date_e" type="text" class="calendar" id="date_e" style="width: 70px;cursor:pointer;" maxlength="19" :value="listConditions.date_e" readonly />
					<i class="icon-calendar calendar-tgr" id="date_e_tgr"></i>
					&nbsp;
					<button class="pure-button pure-button-edit" title="查找" @@click.prevent="listRefresh(1)">
						<i class="icon-search"></i>查找
					</button>
					&nbsp;
					<button class="pure-button pure-button-cancel" title="取消" @@click.prevent="searchReset">
						<i class="icon-rotate-left"></i>重置
					</button>
					&nbsp;&nbsp;
				</td>
				<td class="small" valign="top">
					<input class="windLayerBtclose" type="button" title="" @@click.prevent="searchToggle">
				</td>
			</tr>
		</tbody>
	</table>
</div>
<table class="lvt small table100" style="">
	<tr>
		<td style="padding-left: 30px;" align="left" nowrap>
			<button class="pure-button pure-button-edit" @@click.prevent="listAdd">
				<i class="icon-plus"></i>&nbsp;新增
			</button>
			&nbsp;
			<button class="pure-button pure-button-danger" @@click.prevent="listBatchDelete">
				<i class="icon-trash"></i>&nbsp;批量删除
			</button>
			&nbsp;
			<button class="pure-button pure-button-share" onclick="togglePanelR(this,'divExport');return false;"
					onmouseout="hidePanel('divExport')">
				<i class="icon-upload"></i>&nbsp;导出
			</button>
			&nbsp;
			<div id="divExport" class="list-bulk-div" onmouseout="hidePanel('divExport')" onmouseover="showPanel('divExport')">
				<div onclick="exportAll();">
					<i class="icon-upload" style="padding: 0px 10px;"></i>导出全部
				</div>
				<div class="list-bulk-link" onclick="exportCurrent();">
					<i class="icon-cloud-upload" style="padding: 0px 10px;"></i>导出当前页
				</div>
				<div onclick="exportSelected();">
					<i class="icon-upload" style="padding: 0px 10px;"></i>导出选中
				</div>
			</div>
		</td>
		<td nowrap align="right" valign="middle">
			<table border="0" cellspacing="0" cellpadding="0" class="small">
				<tbody>
					<tr>
						<td style="padding-right: 5px">
							<vue-pagination :total="listData.total" :psize="listData.psize" :pnum="listData.pnum" @@change="pageChangeHandler"></vue-pagination>
						</td>
					</tr>
				</tbody>
			</table>
		</td>
	</tr>
</table>
<div style="width:100%;overflow:auto;">
	<table class="crm-table table100 padding2" cellspacing="1" cellpadding="3" style="table-layout:fixed;">
		<caption v-show="listData.list.length==0">
			暂无数据
		</caption>
		<tr class="windLayerHead">
			<td style="width: 30px;">
				<input type="checkbox" name="selectall" @@click="listToggle($event)" v-model="listData.checked" />
			</td>
			<td v-for="(col,idx) in userColumns" :style="col.hdStyles">
				<a class='listFormHeaderLinks' @@click="listSort(col.name)" v-if="col.sort">{{col.title}}<i :class="{'icon-caret-up':listSortColumn.order=='asc','icon-caret-down':listSortColumn.order=='desc'}" v-if="col.name==listSortColumn.name"></i></a>
				<span v-else>{{col.title}}</span>
			</td>
			<td nowrap style="">
				操作
			</td>
		</tr>
		<tr v-for="(item,idx) in pageList" :rid="item.ID" :class="{'crm-table-plural':idx%2==1}" style="cursor: pointer;">
			<td>
				<input type="checkbox" name="rowid" :value='item.ID' :data-idx="idx" @@click="listCheck($event)" :checked="item.CheckedState" />
			</td>
			<td v-for="(col,cidx) in userColumns" :style="item.Styles[cidx]">
				<a :href="item.Links[cidx].href" v-if="item.Links[cidx].href">{{item[col.name]}}</a>
				<span v-else>{{item[col.name]}}</span>
			</td>
			<td nowrap>
				<i class="icon-edit pure-icon-bu crm-bu-style list-action-btn" title='修改' style="" @@click="listEdit(item)"></i>
				<i class="icon-trash pure-icon-bu crm-bu-style list-action-btn" title='删除' style="" @@click="listDelete(item)"></i>
			</td>
		</tr>
		<tr class="windLayerHead">
			<td style="text-align:right;" colspan="7">总合计</td>
			<td style="text-align:right;">{{listData.listsumtotal.length>0?listData.listsumtotal[0]:0}}</td>
			<td style="text-align:right;">{{listData.listsumtotal.length>1?listData.listsumtotal[1]:0}}</td>
			<td style="text-align:right;">{{listData.listsumtotal.length>2?listData.listsumtotal[2]:0}}</td>
			<td style="" colspan="4"></td>
		</tr>
	</table>
</div>
@*生成列表操作*@
@section footer {
	@*日期必须开始*@
	<script src="~/lib/laydate/laydate.js" asp-append-version="true"></script>
	@*日期必须结束*@
	@*列表相关开始*@
	<script type="text/javascript">
		var listConditionsInit = { state: "" };//初始查询条件
		var pageEnumData = {
			state:@(Json.Serialize(ViewBag.StateOptions)),
			recvstate:@(Json.Serialize(ViewBag.RecvStateOptions)),
			recvtype:@(Json.Serialize(ViewBag.BuzTypeOptions)),
		};
		var pageData = {
			hideBreadcrumb: false,
			serviceCode: '@(ViewBag.ServiceCode)',
			global: globalData,
			listData: {
				checked:false,
				list: [],
				total: 0,
				pnum: 1,
				psize: 20,
				sumcol: [],
				listsumtotal: [],
				pagesumtotal: []
			},
			userColumns: [
				{
					title: "流水号",
					name: "SNo",
					href: '@(Url.Action("ViewDetail", "FinanceRecvDue"))/{ID}',
					hdStyles: {
						width: "120px"
					},
					bdStyles: {
					}
				},
				{
					title: "布行名",
					name: "PartnerName",
					hdStyles: {
						width: "270px"
					},
					bdStyles: {
					}
				},
				{
					title: "相关业务类型",
					name: "BuzType",
					hdStyles: {
						width: "140px",
						textAlign: "center",
					},
					bdStyles: {
						textAlign: "center",
					}
				},
				{
					title: "相关业务单号",
					name: "BuzSNo",
					hdStyles: {
						width: "140px"
					},
					bdStyles: {
					}
				},
				{
					title: "期次",
					name: "Stage",
					hdStyles: {
						width: "60px",
						textAlign: "center",
					},
					bdStyles: {
						textAlign: "center"
					}
				},
				{
					title: "应收日期",
					name: "DueDate",
					hdStyles: {
						width: "70px",
						textAlign: "center",
					},
					bdStyles: {
						textAlign: "center",
					}
				},
				{
					title: "应收金额",
					name: "TotalRecvDue",
					hdStyles: {
						width: "70px",
						textAlign:'right'
					},
					bdStyles: {
						fontWeight: "bold",
						textAlign: 'right'
					}
				},
				{
					title: "已收金额",
					name: "TotalRecved",
					hdStyles: {
						width: "70px",
						textAlign: 'right'
					},
					bdStyles: {
						fontWeight: "bold",
						textAlign: 'right'
					}
				},
				{
					title: "未收金额",
					name: "TotalRecvLeft",
					hdStyles: {
						width: "70px",
						textAlign: 'right'
					},
					bdStyles: {
						fontWeight: "bold",
						textAlign: 'right'
					}
				},
				{
					title: "状态",
					name: "RecvState",
					hdStyles: {
						width: "70px",
						textAlign: "center",
					},
					bdStyles: {
						textAlign: "center",
					}
				},
				{
					title: "创建人",
					name: "AddManName",
					hdStyles: {
						width: "80px"
					},
					bdStyles: {
					}
				},
				{
					title: "创建时间",
					name: "AddDate",
					hdStyles: {
						width: "120px"
					},
					bdStyles: {
					}
				}
			],
			searchShow:true,
			listConditions: Object.assign({}, listConditionsInit),
			listSortColumn: {
				name: "",
				order:""
			},
			listStyles: {
				"BuzType": {
					"@((int)ST.Buz.Base.Enums.FinanceBuzType.加工订单)": { color:"#FFCC00"},
				}
			},
			model: {},
		};

		var pageApp = new Vue({
			el: '#app',
			data: pageData,
			mounted: function () {
				this.listRefresh();
			},
			methods: {
				pageChangeHandler: function (args) {
					this.listRefresh(args.pnum, args.psize)
				},
				listRefresh: function (pageNum, pageSize) {
					var _params = Object.assign({}, {
						pnum: pageNum || this.listData.pnum,
						psize: pageSize || this.listData.psize,
						sortby: !this.listSortColumn.name ? "" : this.listSortColumn.name + "_" + this.listSortColumn.order
					}, this.listConditions);
					var _this = this;
					utils.ajaxPost('@(Url.Action("Search", "FinanceRecvDue"))', _params, function (resp) {
						var list = resp.data.list.map(function (item) {
							return Object.assign({}, item, {
								CheckedState: false
							});
						});
						var pagesumtotal;
						if (resp.data.sumcol) {
							pagesumtotal = resp.data.sumcol.map(function (col) {
								return resp.data.list.reduce(function (total, cur) {
									return total + cur[col];
								}, 0);
							});
						}
						var newData = { sumcol: resp.data.sumcol, listsumtotal: resp.data.sumtotal, pagesumtotal: pagesumtotal, list: list, total: resp.data.total, pnum: resp.data.pnum, psize: resp.data.psize ,checked:false};
						_this.listData = newData;
					}, function (err) {
					})
				},
				searchReset: function () {
					this.listConditions = Object.assign({}, listConditionsInit);
					this.listSortColumn = {
						col: "",
						order: ""
					};
					this.listRefresh(1);
				},
				searchToggle: function () {
					this.searchShow = !this.searchShow;
				},
				listSort: function (col) {
					if (col != this.listSortColumn.name) {
						this.listSortColumn.order = "desc";
						this.listSortColumn.name = col;
					} else {
						this.listSortColumn.order = this.listSortColumn.order == "asc" ? "desc" : "asc";
					}
					this.listRefresh(1);
				},
				listToggle: function (e) {
					var checked = (e.srcElement || e.target).checked;
					this.listData.list=this.listData.list.map(function (item) {
						return Object.assign({}, item,{
							CheckedState: checked
						});
					});
				},
				listCheck: function (e) {
					var obj = e.srcElement || e.target;
					var checked = obj.checked;
					this.listData.list[obj.dataset.idx].CheckedState = checked;
				},
				listAdd: function () {
					location.href = '@(Url.Action("Add", "FinanceRecvDue"))?nc=' + new Date().getTime();
				},
				listEdit: function (item) {
					location.href = '@(Url.Action("Edit", "FinanceRecvDue"))/' + item.ID + '?nc=' + new Date().getTime();
				},
				listDelete: function (item) {
					var _this = this;
					utils.confirm('确定要删除应付款【' + item.SNo +'】？', function () {
						utils.ajaxPost('@(Url.Action("Delete", "FinanceRecvDue"))', { id: item.ID }, function (resp) {
							utils.success("删除成功");
							_this.listRefresh();
						}, function (msg) {
							utils.alert(msg);
						});
					});
				},
				listBatchDelete: function () {
					var selected = this.listData.list.filter(function (item) {
						return item.CheckedState;
					});
					var ids = selected.map(function (item) {
						return item.ID;
					});
					if (!ids||ids.length == 0) {
						utils.alert('请先选择要删除的应付款');
						return;
					}
					var _this = this;
					utils.confirm('确定要删除所选择的应付款？', function () {
						utils.ajaxPost('@(Url.Action("BatchDelete", "FinanceRecvDue"))',  ids , function (resp) {
							utils.success("删除成功");
							_this.listRefresh();
						}, function (msg) {
							utils.alert(msg);
						});
					});
				}
			},
			computed: {
				pageList: function () {
					var _this = this;
					return this.listData.list.map(function (item) {
						return Object.assign({}, item, {
							StateNow: _this.$options.filters.formatState(item.StateNow),
							RecvState: _this.$options.filters.formatRecvState(item.RecvState),
							DueDate: _this.$options.filters.formatDate(item.DueDate, 'yyyy-MM-dd'),
							BuzType: _this.$options.filters.formatBuzType(item.BuzType),
							Styles: _this.userColumns.map(function (col) {
								return Object.assign({}, col.bdStyles, _this.listStyles[col.name] ? _this.listStyles[col.name][item[col.name]] : {})
							}),
							Links: _this.userColumns.map(function (col) {
								return Object.assign({}, { href: col.href ? col.href.replace(/{ID}/g, item.ID) : "" });
							}),
						});
					});
				},
				currentM: function () {
					var currentM = null;
					var i;
					var j;
					for (i = 0; i < this.global.modules.length; i++) {
						for (j = 0; j < this.global.modules[i].Services.length; j++) {
							if (this.serviceCode == this.global.modules[i].Services[j].Code) {
								currentM = this.global.modules[i];
								break;
							}
						}
					}
					return currentM;
				},
				currentS: function () {
					var currentS = null;
					var i;
					var j;
					for (i = 0; i < this.global.modules.length; i++) {
						for (j = 0; j < this.global.modules[i].Services.length; j++) {
							if (this.serviceCode == this.global.modules[i].Services[j].Code) {
								currentS = this.global.modules[i].Services[j];
								break;
							}
						}
					}
					return currentS;
				}
			},
			filters: {
				formatState: function (val) {
					return utils.formatEnum(val, pageEnumData.state);
				},
				formatRecvState: function (val) {
					return utils.formatEnum(val, pageEnumData.recvstate);
				},
				formatBuzType: function (val) {
					return utils.formatEnum(val, pageEnumData.recvtype);
				}
			}
		});

		function openPopPartner() {
			utils.layerFull('@(Url.Action("PopList", "IMS_Partner"))?type=@((int)PartnerType.布行)&callback=popPartnerCallback', "选择客户", "Partner");
		}

		function popPartnerCallback(index, ret) {
			if (!ret) {
				return;
			}
			pageData.listConditions = Object.assign({}, pageData.listConditions, {
				partnerid: ret.ID,
				partnername: ret.Name
			});
			pageApp.listRefresh(1);
		}

		function clearPopPartner() {
			pageData.listConditions = Object.assign({}, pageData.listConditions, {
				partnerid: "0",
				partnername : ""
			});
			pageApp.listRefresh(1);
		}

		$(document).ready(function () {
			$('.calendar-tgr').each(function (eidx, elem) {
				var $this = $(elem);
				var input = $this.prev('input')[0];
				$this.click(function () {
					laydate.render({
						elem: input
						, show: true //直接显示
						, closeStop: $this[0]
						, done: function (value, date) {
							pageData.listConditions = Object.assign({}, pageData.listConditions, _defineProperty({}, input.name, value));
						}
					});
				});
			});

			$('.calendar').each(function (eidx, elem) {
				var $this = $(elem);
				var input = $this[0];
				laydate.render({
					elem: input
					, closeStop: $this.next('i')[0]
					, done: function (value, date) {
						pageData.listConditions = Object.assign({}, pageData.listConditions, _defineProperty({}, input.name, value));
					}
				});
			});
		});

		$(function () {
			if(isMobile())
			{
				window.location.href="@Url.Action("MobileList", "FinanceRecvDue")";
			}
		});

		function isMobile() {
		  const regExp = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i;
		  return regExp.test(navigator.userAgent);
		}
	</script>
	@*列表相关结束*@
	@*导出相关开始*@
	<script type="text/javascript">
		function exportAll() {
		}

		function exportCurrent() {
		}

		function exportSelected() {
		}
	</script>
	@*导出相关结束*@
}
